package com.web.common.dataDictionary.PO;

import java.util.*;
import com.css.sword.kernel.base.annotation.*;
import com.css.sword.kernel.base.dataElement.*;
import com.css.sword.kernel.base.exception.SwordBaseCheckedException;

import com.web.common.dataDictionary.DE.DE_ID;
import com.web.common.dataDictionary.DE.DE_CATEGORYNAME;
import com.web.common.dataDictionary.DE.DE_OPPTIME;
import com.web.common.dataDictionary.DE.DE_BZ;


/**
 * 商品分类表
 */
@PersistObject
public class TabGoodscategoryPO extends AbsPersistObject {
	//private static final long serialVersionUID = 5578721762240821032L;
	private static final long serialVersionUID = 1L;
	private static final Map<String, Integer> fieldIndex = new HashMap<String, Integer>(4);
	private static final BitSet HAS_DEFAULT_VALUE = new BitSet(4);
	
	static{
		fieldIndex.put("id",0);fieldIndex.put("categoryname",1);fieldIndex.put("opptime",2);fieldIndex.put("bz",3);
	}
	
	/**
	 * 物理表名
	 */
	public static final String TABLE_NAME = "tab_goodscategory";

	/**
	 * 主键id
	 */
	private DE_ID id = DE_ID.getTemplateInstance();

	/**
	 * 商品分类名称
	 */
	private DE_CATEGORYNAME categoryname = DE_CATEGORYNAME.getTemplateInstance();

	/**
	 * 操作时间
	 */
	private DE_OPPTIME opptime = DE_OPPTIME.getTemplateInstance();

	/**
	 * 商品分类备注
	 */
	private DE_BZ bz = DE_BZ.getTemplateInstance();


	public TabGoodscategoryPO(){
		this.insertState = new BitSet(4);
		this.updateState = new BitSet(4);
	}

	
	/**
	 * 获取 "主键id" 值
	 */	
	public DE_ID getId(){
		return  id;
	}
	
	/**
	 * 设置 "主键id" 值
	 */
	public void setId(DE_ID id) {
		if(id == null){
			id= DE_ID.getTemplateInstance();
		}
		recordChangeFlag(0);
		this.id = id;
	}
	
	/**
	 * 获取 "商品分类名称" 值
	 */	
	public DE_CATEGORYNAME getCategoryname(){
		return  categoryname;
	}
	
	/**
	 * 设置 "商品分类名称" 值
	 */
	public void setCategoryname(DE_CATEGORYNAME categoryname) {
		if(categoryname == null){
			categoryname= DE_CATEGORYNAME.getTemplateInstance();
		}
		recordChangeFlag(1);
		this.categoryname = categoryname;
	}
	
	/**
	 * 获取 "操作时间" 值
	 */	
	public DE_OPPTIME getOpptime(){
		return  opptime;
	}
	
	/**
	 * 设置 "操作时间" 值
	 */
	public void setOpptime(DE_OPPTIME opptime) {
		if(opptime == null){
			opptime= DE_OPPTIME.getTemplateInstance();
		}
		recordChangeFlag(2);
		this.opptime = opptime;
	}
	
	/**
	 * 获取 "商品分类备注" 值
	 */	
	public DE_BZ getBz(){
		return  bz;
	}
	
	/**
	 * 设置 "商品分类备注" 值
	 */
	public void setBz(DE_BZ bz) {
		if(bz == null){
			bz= DE_BZ.getTemplateInstance();
		}
		recordChangeFlag(3);
		this.bz = bz;
	}


	@Override
	public BaseDataElement<?>[] fields(){
		return new BaseDataElement<?>[] {id,categoryname,opptime,bz};
	}
	
	@Override
	public String[] fieldNames() {
		return new String[]{"id","categoryname","opptime","bz"};
	}
	
	@Override
	public BaseDataElement<?> getFieldValue(String fieldName)  {
		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
		switch (index) {
		case 0 : return id;
		case 1 : return categoryname;
		case 2 : return opptime;
		case 3 : return bz;
 
		default:
			throw new IllegalArgumentException("PO对象中没有" + fieldName + "字段");
		}
	}
	
	@Override
	public TabGoodscategoryPO setFieldValue(String fieldName, Object fieldValue) throws SwordBaseCheckedException {
		if (fieldValue != null && !(fieldValue instanceof BaseDataElement<?>)) {
			throw new SwordBaseCheckedException("字段值类型不是DataElelement子类型");
		}

		final Integer index = fieldIndex.get(fieldName);
		if (index == null) {
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}

		switch (index) {

				case 0 : {
					if (fieldValue == null) {
						setId(null);
					} else {
						setId((DE_ID) fieldValue);
					}
					return this;
				}
				
				case 1 : {
					if (fieldValue == null) {
						setCategoryname(null);
					} else {
						setCategoryname((DE_CATEGORYNAME) fieldValue);
					}
					return this;
				}
				
				case 2 : {
					if (fieldValue == null) {
						setOpptime(null);
					} else {
						setOpptime((DE_OPPTIME) fieldValue);
					}
					return this;
				}
				
				case 3 : {
					if (fieldValue == null) {
						setBz(null);
					} else {
						setBz((DE_BZ) fieldValue);
					}
					return this;
				}
				
		default:
			throw new SwordBaseCheckedException("PO对象中没有" + fieldName + "字段");
		}
	
	}

	@Override
	protected TabGoodscategoryPO clone() {
		TabGoodscategoryPO t = new TabGoodscategoryPO();
		
		t.setId(this.id);
		t.setCategoryname(this.categoryname);
		t.setOpptime(this.opptime);
		t.setBz(this.bz);

		return t;
	}

	@Override
	public TabGoodscategoryPO loadMap(Map<String, Object> dataMap) throws SwordBaseCheckedException {
		Object value = null;

		if(dataMap.containsKey("id")){
			value = dataMap.get("id");
			
			if (value == null) {
				this.setId(null);
			} else {
				if (value instanceof DE_ID) {
					this.setId((DE_ID) value);
				}
			    else {
					this.setId(new DE_ID(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("categoryname")){
			value = dataMap.get("categoryname");
			
			if (value == null) {
				this.setCategoryname(null);
			} else {
				if (value instanceof DE_CATEGORYNAME) {
					this.setCategoryname((DE_CATEGORYNAME) value);
				}
			    else {
					this.setCategoryname(new DE_CATEGORYNAME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("opptime")){
			value = dataMap.get("opptime");
			
			if (value == null) {
				this.setOpptime(null);
			} else {
				if (value instanceof DE_OPPTIME) {
					this.setOpptime((DE_OPPTIME) value);
				}
				else if(value instanceof java.util.Date){
					this.setOpptime(new DE_OPPTIME((java.util.Date)value));
				}
			    else {
					this.setOpptime(new DE_OPPTIME(value.toString()));
				}
			}
		}

		if(dataMap.containsKey("bz")){
			value = dataMap.get("bz");
			
			if (value == null) {
				this.setBz(null);
			} else {
				if (value instanceof DE_BZ) {
					this.setBz((DE_BZ) value);
				}
			    else {
					this.setBz(new DE_BZ(value.toString()));
				}
			}
		}

		return this;
	}
	
	@Override
	public Map<String,Object> toMap() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("id", id);
		dataMap.put("categoryname", categoryname);
		dataMap.put("opptime", opptime);
		dataMap.put("bz", bz);
		
		return dataMap;
	}
	
	@Override
	public Map<String,Object> toMapWithDEValue() {
		Map<String,Object> dataMap = new HashMap<String,Object>();

		dataMap.put("id", (id==null?null:id.value));
		dataMap.put("categoryname", (categoryname==null?null:categoryname.value));
		dataMap.put("opptime", (opptime==null?null:opptime.value));
		dataMap.put("bz", (bz==null?null:bz.value));
		
		return dataMap;
	}
	
	@Override
	public TabGoodscategoryPO newInstance() {
		return new TabGoodscategoryPO();
	}
	
	@Override
	public String getTableName(){
		return TABLE_NAME;
	}
	
	@Override
	public BaseDataElement<?>[] getPrimaryKey() {
		return new BaseDataElement<?>[]{id};
	}

	@Override
	public void checkNotNull(byte sqlType) throws SwordBaseCheckedException {
		StringBuilder errorMsg = new StringBuilder();
		// insert
		if (sqlType == 0) {
				//只校验不可为空但又没有默认值的字段
				if (id.value == null && !HAS_DEFAULT_VALUE.get(0)) {
					errorMsg.append("字段id不允许为空\n");
				}

		}
		// update
		else if (sqlType == 1) {
		if (updateState.get(0) && id.value == null) {
			errorMsg.append("字段id不允许为空\n");
		}

		}
		
		if (errorMsg.length() > 0) {
			errorMsg.setLength(errorMsg.length() - 1);
			throw new SwordBaseCheckedException(errorMsg.toString());
		}
	}

	@Override
	public void updateLrrq(DateDE lrrq) {
	}

	@Override
	public void updateXgrq(DateDE xgrq) {
	}

	@Override
	public String toString() {
		StringBuilder str = new StringBuilder();
		str.append("id:").append(id.value!=null?id:"").append(" ").append("categoryname:").append(categoryname.value!=null?categoryname:"").append(" ").append("opptime:").append(opptime.value!=null?opptime:"").append(" ").append("bz:").append(bz.value!=null?bz:"").append(" ");
		return str.toString();
	}
	
}
